<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class AdminModel extends Model
{
    //管理员信息表
    protected $table = 'admin';  //数据表
    protected $schema=[
        'admin_id' => 'int',
        'admin_account' => 'string',
        'admin_name' => 'string',
        'admin_password' => 'string',
        'admin_identity' => 'int',
        'admin_register_time' => 'datetime',

    ];
    protected $createTime = 'admin_register_time';
    protected $pk = 'admin_id';  //主键

//    通过token获取管理员id
    public static function getAdmindByToken($token)
    {
        return AdminLoginRecord::where('admin_token',$token)->find()->admin_id;
    }

    //    通过管理员id获取管理员名
    public static function getNameByUserid($admin_id)
    {
        return AdminModel::where('admin_id',$admin_id)->find()->admin_name;
    }

    //    通过管理员id获取管理员信息
    public static function getInfoByUserid($admin_id)
    {
        return AdminModel::where('admin_id',$admin_id)->field('admin_id,admin_account,admin_name,admin_identity')->find();
    }

//    获取所有管理员信息
    public static function getAllAdminInfo()
    {
        return AdminModel::order('admin_register_time','desc')
            ->where('admin_token','<>','super')
            ->field('admin_id,admin_account,admin_name,admin_register_time')
            ->select();
    }

}
